/*
This file is part of SmartShopper

SmartShopper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SmartShopper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vlc-remote.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.1
import com.meego 1.0

Page {
    id: listsPage
    tools: CommonTools {id: commonTools}
    property string helpText: "Help page for Lists"
//    property color textColor: theme.inverted ? "White" : "Black"

    function iconChange() {
        listControl.sortDown = !listControl.sortDown
    }

    function sortChange(ixd) {
        listControl.sortOrder = ixd
    }

    ListModel {
        id: sortModel
        ListElement { name: QT_TR_NOOP("by Name") }
        ListElement { name: QT_TR_NOOP("by Shop") }
        ListElement { name: QT_TR_NOOP("by Status") }
    }

    PageHeader {
        id: pageHeader
        anchors.top: parent.top
        title: qsTr("Shopping Lists")
        iconDown: "toolbar-down"
        iconUp: "toolbar-up"
        color: "orangered"
        sortDown: listControl.sortDown
        sortOrder: listControl.sortOrder
        dialogModel: sortModel
        dialogCaption: qsTr("Select sort order")
        Component.onCompleted: {
            iconClicked.connect(listsPage.iconChange);
            dialogAccpeted.connect(listsPage.sortChange)
        }
    }

    Menu {
        id: itemMenu
        visualParent: pageStack
        MenuLayout {
            MenuItem { text: qsTr("Delete"); onClicked: { listControl.deleteItem(lists.currentIndex) }}
//            MenuItem { text: "Exit"; onClicked: { Qt.quit() } }
        }
    }


//    InfoBanner {
//        id: sb
//        text: "This is an info banner with no icon"
//    }
    Component {
        id: listDelegate
        Item{
            height: 64; width: parent.width
            Row {
                Item {height:64; width: 8}
                Column {
                    Item {height:4; width: listsPage.width}
                    Text { text: listName
                        font.pointSize: 20
                        font.bold: true
                        //                   anchors.centerIn: parent;
                        color: appWindow.textColor
                    }
                    Text { text: shopName
                        font.pointSize: 16
                        font.italic: true
                        //anchors.centerIn: parent;
                        color: appWindow.textColor
                    }
                    Item {height:4; width: listsPage.width}
                    Rectangle {
                        height:1;
                        width: listsPage.width;
                        opacity: 0.5;
                        color: theme.inverted ? "White" : "Black"
                    }
                }

            }
            MouseArea {
                anchors.fill: parent
                onPressed: {
                    lists.currentIndex = index
                }
                onPressAndHold:{ itemMenu.open()}
            }
        }
    }

    ListView {
        id: lists
        anchors {
            top: pageHeader.bottom
            bottom: parent.bottom
        }
        width: parent.width // - 10
        model: listModel
        delegate: listDelegate
        focus: true
        currentIndex: -1
        highlight: Rectangle { color: "orange"; radius: 5}
    }
    focus: true
}
